package com.xdf.config;

import com.mybatisflex.core.FlexGlobalConfig;
import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;

import javax.annotation.PostConstruct;
import javax.sql.DataSource;

/**
 * @author chanchaw
 * @create 2024-09-18 19:21
 */
@Configuration
public class MybatisFlexConfig {
    @PostConstruct
    public void init(){
        FlexGlobalConfig globalConfig = FlexGlobalConfig.getDefaultConfig();
        FlexGlobalConfig.getDefaultConfig().setLogicDeleteColumn("is_delete");
        //设置数据库正常时的值
        globalConfig.setNormalValueOfLogicDelete(0);
        //设置数据已被删除时的值
        globalConfig.setDeletedValueOfLogicDelete(1);
    }

//    @Bean
//    public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
//        SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        sessionFactory.setDataSource(dataSource);
//        sessionFactory.setMapperLocations(
//                new PathMatchingResourcePatternResolver()
//                        .getResources("classpath:/mapping/*.xml"));
//        return sessionFactory.getObject();
//    }

}
